package org.zsl.controller.servlet;

import org.zsl.model.User;
import org.zsl.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class LoginController extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


       String username=  request.getParameter("username");
       String password= request.getParameter("password");


       User user = new User();
       user.setUsername(username);
       user.setPassword(password);

      Boolean isSuccess=  userService.login(user);

      response.getWriter().write(isSuccess.toString());

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=  request.getParameter("username");
        String password= request.getParameter("password");


        User user = new User();
        user.setUsername(username);
        user.setPassword(password);

        Boolean isSuccess=  userService.login(user);

        response.getWriter().write(isSuccess.toString());

    }
}
